import requests
from bs4 import BeautifulSoup
import json
from html.parser import HTMLParser
import html

url = "https://jbk.39.net/mxyy/jbzs/"
# get_param = {
#     "channelid": "CHAL1460955853485115", "area": "", "sc": "", "fc": "电视剧", "year": "", "letter": "", "p": "1",
#     "n": "1181", "serviceId": "tvcctv", "topv": "1", "t": "jsonp", "cb": "Callback"
# }
UA = {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}
r = requests.get(url, headers = UA)
html = r.content.decode('utf-8', 'ignore')
my_page = BeautifulSoup(html, 'lxml')

for tag in my_page.find_all('div', class_='disease'):
    disease = tag.find('h1').get_text()
    disease_name = disease

for tag in my_page.find_all('p', class_='introduction'):
    introduction = tag.get_text()
    disease_introduction = introduction

for tag in my_page.find_all('div', class_='list_left'):
    sub_tag = tag.find('ul',class_="disease_basic")
    my_span = sub_tag.findAll('span')
    #my_span is a list
    is_yibao = my_span[1].text    #是否医保
    othername = my_span[3].text   #别名
    fbbw = my_span[5].text        #发病部位
    is_infect = my_span[7].text   #传染性
    dfrq = my_span[9].text        #多发人群
    my_a = sub_tag.findAll('a')
    xgzz = my_a[2].text+' '+my_a[3].text+' '+my_a[4].text  #相关症状
    #ps: .contents[0] or .get_text() is also accepted

# Some tests:
# print(html)
# print(my_page)
# print(sub_tag)
# print(xgzz)
# print(my_span)
# print(my_span[1])
print(othername)
print('over')




